package com.zk.iotgateway.net;


import com.zk.iotgateway.manager.GlobalManager;
import com.zk.iotgateway.service.IServerService;

/**
 * @Author mn
 * @Description  抽象服务基类
 * @Date 下午 05:25 2019/7/2 0002
 * @return
 **/
public abstract class AbstractServerService implements IServerService {

    private final String servicePort;

    protected byte serviceState;

    public AbstractServerService(String servicePort) {
        this.servicePort = servicePort;
        this.initialize();
    }


    /*
    * 获取服务端口
    * */
    @Override
    public final String getServicePort() {
        return servicePort;
    }

    @Override
    public boolean initialize() {
        GlobalManager.getInstance().registerService(servicePort, this);
        return true;
    }
    @Override
    public void release() {
        //从全局服务管理器移除自己
        GlobalManager.getInstance().removeService(servicePort);
    }

    @Override
    public boolean startService(){
        return true;
    }

    @Override
    public boolean stopService() throws Exception{
        return true;
    }

    @Override
    public final byte getState() {
        return serviceState;
    }

    @Override
    public final boolean isRunning() {
        return true;
    }
}